import axios from 'axios'
var host = 'http://127.0.0.1:8080/datastealer';
// 获取数据源信息
export function getDataSource() {
    return new Promise(resolve => {
        axios.get(host + '/dataSource', {
        }).then(function (res) {
            resolve(res.data);
        });
    });
}
// 获取schema
export function getSchema() {
    return new Promise(resolve => {
        axios.get(host + '/schema', {
        }).then(function (res) {
            resolve(res.data);
        });
    });
}
// 获取table
export function getTable(schemaName) {
    return new Promise(resolve => {
        axios.get(host + '/schema/' + schemaName + '/table', {
        }).then(function (res) {
            resolve(res.data);
        });
    });
}
// 获取table的ddl
export function getTableDDL(schemaName, tableName) {
    return new Promise(resolve => {
        axios.get(host + '/schema/' + schemaName + '/table/' + tableName + '/ddl', {
        }).then(function (res) {
            resolve(res.data);
        });
    });
}
// 获取table字段
export function getTableColumns(schemaName, tableName) {
    return new Promise(resolve => {
        axios.get(host + '/schema/' + schemaName + '/table/' + tableName + '/column', {
        }).then(function (res) {
            resolve(res.data);
        });
    });
}

// 获取table数据
export function getDataByPage(schemaName, tableName, pageNum, pageSize) {
    return new Promise(resolve => {
        axios.get(host + '/schema/' + schemaName + '/table/' + tableName + '/data?pageNum=' + pageNum + "&pageSize=" + pageSize, {
        }).then(function (res) {
            resolve(res.data);
        });
    });
}
// 执行用户自定义sql
export function runCustomSql(sql) {
    return new Promise(resolve => {
        axios.post(host + '/runCustomSql', sql, {
            headers: {
                'Content-Type': 'text/plain'
            }
        }).then(function (res) {
            resolve(res.data);
        });
    });
}